<!--
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/3/6-16:34
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------
*-->

{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12" >

    <div class="layui-card" >

        <div class="layui-card-body" >

            <div class="layui-form" lay-filter="" >

                <div class="layui-form-item" style="margin-top: 15px;" >
                    <label class="layui-form-label" >微信商户ID<br ><span class="nowrap color-desc" >MCH_ID</span ></label >
                    <div class="layui-input-block" >
                        <input name="wechat_mch_id" lay-verify="required" lay-vertype="tips" placeholder="请输入微信商户ID（必填）"
                               value="{:configGet('wechat_mch_id')}" class="layui-input" >
                        <p class="help-block" >微信商户ID，需要在微信商户平台获取，MCH_ID 与 APPID 匹配</p >
                    </div >
                </div >

                <div class="layui-form-item" >
                    <label class="layui-form-label" >微信商户KEY<br ><span
                            class="nowrap color-desc" >MCH_KEY</span ></label >
                    <div class="layui-input-block" >
                        <input name="wechat_mch_key" placeholder="请输入微信商户密钥（必填）" maxlength="32" lay-verify="required"
                               lay-vertype="tips" value="{:configGet('wechat_mch_key')}" class="layui-input" >
                        <p class="help-block" >微信商户密钥，需要在微信商户平台操作设置密码并获取密钥</p >
                    </div >
                </div >

                <div class="layui-form-item" >
                    <label class="layui-form-label" >微信商户证书<br ><span
                            class="nowrap color-desc" >MCH_CERT</span ></label >
                    <div class="layui-input-block" >
                        <input type="radio"  name="wechat_mch_ssl_type" value="pem" title="上传 PEM 证书"  lay-filter="data-mch-type" >
                        <input type="radio"  name="wechat_mch_ssl_type" value="p12" title="上传 P12 证书"  lay-filter="data-mch-type" checked>
                        <p class="help-block">请选择需要上传证书类型，P12 和 PEM 二选一，证书需要从微信商户平台获取</p>
                    </div >
                </div >

                <div class="layui-form-item p12z" >
                    <label class="layui-form-label" >P12证书</label>
                    <div class="layui-input-block" >
                        <input name="wechat_mch_ssl_p12" value="{$wechat_mch_ssl_p12|default=''}" id="p12" type="hidden">
                        <button id="up_p12" type="button" class="layui-btn layui-btn-primary">
                            <i class="layui-icon layui-icon-vercode font-s14"></i> 上传 P12 证书
                        </button>
                        <p class="help-block margin-top-10">微信商户支付 P12 证书，实现订单退款、打款、发红包等支出功能都使用证书</p>
                    </div >
                </div >

                <div class="layui-form-item pemz"  style="display: none;">
                    <label class="layui-form-label" >Pem证书</label>
                    <div class="layui-input-block" >
                        <input name="wechat_mch_ssl_key" value="{$wechat_mch_ssl_key|default=''}" id="pem_key" type="hidden">
                        <button id="pem_key_up" type="button" class="layui-btn layui-btn-primary margin-right-5">
                            <i class="layui-icon layui-icon-vercode font-s14"></i> 上传 KEY 证书
                        </button>
                        <input name="wechat_mch_ssl_cer" value="{$wechat_mch_ssl_cer|default=''}" id="pem_cert" type="hidden">
                        <button id="pem_cert_up" type="button" class="layui-btn layui-btn-primary">
                            <i class="layui-icon layui-icon-vercode font-s14"></i> 上传CERT证书
                        </button>
                        <p class="help-block margin-top-10">微信商户支付 PEM 双向证书，实现订单退款、打款、发红包等支出功能都使用证书</p>
                    </div >
                </div >

                <div class="layui-form-item" >
                    <div class="layui-input-block" >
                        <button class="layui-btn" lay-submit="" lay-filter="set_pay" >确认保存</button >
                    </div >
                </div >

            </div >


        </div >
    </div >

</div >


{/block}

{block name="js"} <!--js处理区-->

<script >

    layui.use(['element', 'form', 'jquery', 'lucky','upload'], function () {
        var element = layui.element;
        var form = layui.form;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        let upload = layui.upload;

        form.render();

        //切换pem
        form.on('radio(data-mch-type)', function(data){
            if(data.value == 'pem'){
                $(".p12z").css('display','none');
                $(".pemz").css('display','block');
            }else{
                $(".p12z").css('display','block');
                $(".pemz").css('display','none');
            }
        });

        //p12上传
        upload.render({
            elem:'#up_p12'
            ,size: "1024*12"
            ,accept: 'file'
            ,url: '{:url("admin/common/UpPem")}'
            ,auto:true
            ,before: function(input){
                loading = layer.load(2, {
                    shade: [0.2,'#000'] //0.2透明度的白色背景
                });
            }
            ,done: function(res){
                if (res.code==1){
                    layer.msg(res.msg, {icon: 1, time: 1000},function () {
                        $("#p12").val(res.path);
                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }
            },error:function (index,upload) {
                layer.close(loading);
                layer.msg('上传失败', {icon: 2, anim: 6, time: 1000});
            }
        });


        //pem_key上传
        upload.render({
            elem:'#pem_key_up'
            ,size: "1024*12"
            ,accept: 'file'
            ,url: '{:url("admin/common/UpPem")}'
            ,auto:true
            ,before: function(input){
                loading = layer.load(2, {
                    shade: [0.2,'#000'] //0.2透明度的白色背景
                });
            }
            ,done: function(res){
                if (res.code==1){
                    layer.msg(res.msg, {icon: 1, time: 1000},function () {
                        $("#pem_key").val(res.path);
                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }
            },error:function (index,upload) {
                layer.close(loading);
                layer.msg('上传失败', {icon: 2, anim: 6, time: 1000});
            }
        });


        //pem_cert上传
        upload.render({
            elem:'#pem_cert_up'
            ,size: "1024*12"
            ,accept: 'file'
            ,url: '{:url("admin/common/UpPem")}'
            ,auto:true
            ,before: function(input){
                loading = layer.load(2, {
                    shade: [0.2,'#000'] //0.2透明度的白色背景
                });
            }
            ,done: function(res){
                if (res.code==1){
                    layer.msg(res.msg, {icon: 1, time: 1000},function () {
                        $("#pem_cert").val(res.path);
                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }
            },error:function (index,upload) {
                layer.close(loading);
                layer.msg('上传失败', {icon: 2, anim: 6, time: 1000});
            }
        });

        /**
         * 网站设置提交
         */
        form.on('submit(set_pay)', function (data) {
            lucky.FormSubmit("{:url('config/pay')}", data.field, 0, 0, 1);
            return false;
        });


    });

</script >


{/block}